import pandas as pd
import os
import time
import matplotlib.pyplot  as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter

class sha_report:
    def __init__(self):
        plt.rcParams['font.sans-serif'] = ['Heiti TC']  # 用来正常显示中文标签
        plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
        self.df = pd.read_excel('/Users/user/PycharmProjects/text1/shasta线体站点良率项目/0922设备线体良率匹配表.xlsx')
        print(self.df.columns)
        print(self.df.infer_objects().dtypes)
        # df1 = df1.apply(lambda x: ('%.2f%%' % (x * 100)) if isinstance(x, float) else x)  小数转化为百分数
        self.df = self.df.map(lambda x: float(x.replace('%', ''))/100 if x.endswith('%') else x )  # 以百分号的字符串，全部拿掉百分号，然后转换为小数
        self.df = self.df.replace('待开线', None)
        print(self.df.infer_objects().dtypes)
        print(self.df['L1-0922'])
    def plot(self):
        fig,ax = plt.subplots(1,1)
        fig.subplots_adjust(left=0.11, right=0.95, top=0.925, bottom=0.3)

        for  index  in  self.df.columns.to_list()[2:]:
            ax.plot(self.df['Station Name'],   self.df[index], linestyle='-', label = index , marker='.' )
            # for x,y  in zip(self.df['Station Name'] , self.df[index]):
            #     ax.text(x ,y ,f'{x}:{round(y ,4)}',ha="center",va="bottom",fontsize=10)

        ax.set_title('yield良率')
        ax.legend()
        plt.xticks(rotation=90)
        plt.xlabel('这是x轴的信息')
        ax.yaxis.set_major_locator(MultipleLocator(0.1)) # 将y轴主刻度标签设置为0.2的倍数
        ax.yaxis.set_major_formatter(FormatStrFormatter('%4.3f'))# 设置y轴标签文本的格式
        ax.minorticks_on()
        ax.yaxis.set_minor_locator(MultipleLocator(0.01))# 将此y轴次刻度标签设置为0.1的倍数
        ax.tick_params(axis = 'y' ,direction='in', length=6, width =1, colors='black',
                       grid_color='r', grid_alpha=0.5,which= 'minor'  )
        ax.tick_params(axis='y', direction='in', length=6, width=1, colors='k', which= 'major')
        ax.yaxis.grid(True, which='major')  # y坐标轴的网格使用次刻度
        ax.set_xlabel('x轴')
        ax.set_ylabel('y轴')
        plt.show()

shasta = sha_report()
shasta.plot()
